#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N=402;
const double dealt = 1e-3;
int T;
int n,p,s,t;
double edges[N][N];
LL x[N],y[N];

double getlen(LL x1,LL y1,LL x2,LL y2){
    return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}

int main()
{
    scanf("%d",&T);
    for(int i0=0;i0<T;i0++)
    {
        scanf("%d%d%d%d",&n,&p,&s,&t);
        --s;--t;
        for(int j=0;j<n;j++)
        {
            edges[j][j]=0.0;
            LL price;
            LL xx[4],yy[4];
            scanf("%lld%lld%lld%lld%lld%lld%lld",&xx[0],&yy[0],&xx[1],&yy[1],&xx[2],&yy[2],&price);
            //x4 y4;
            for(int i=0;i<3;i++){
                int p1=(i+1)%3;
                int p2=(i+2)%3;
                xx[3] = xx[p1]+xx[p2]-xx[i];
                yy[3] = yy[p1]+yy[p2]-yy[i];
                if(abs(getlen(xx[i],yy[i],xx[3],yy[3])-getlen(xx[p1],yy[p1],xx[p2],yy[p2]))<dealt){
                    break;
                }
            }
            for(int k=1;k<=4;k++){
                x[4*j+k]=xx[k-1];
                y[4*j+k]=yy[k-1];
            }
            //edges inside city
            for(int u=1;u<=4;u++){
                int i1=4*j+u;
                for(int v=u+1;v<=4;v++){
                    int i2=4*j+v;
                    edges[i1][i2]=edges[i2][i1]=price*getlen(xx[u-1],yy[u-1],xx[v-1],yy[v-1]);
                }
            }
        }
        //edges between city
        for(int j=0;j<n;j++){
            for(int k=j+1;k<n;k++){
                for(int a1=1;a1<=4;a1++){
                    for(int a2=1;a2<=4;a2++){
                        int p1=4*j+a1,p2=4*k+a2;
                        edges[p1][p2]=edges[p2][p1]=getlen(x[p1],y[p1],x[p2],y[p2])*p;
                    }
                }
            }
        }
        //Floyd
        for(int k=1;k<=4*n;k++){
            for(int i=1;i<=4*n;i++){
                for(int j=1;j<=4*n;j++){
                    if(edges[i][k]+edges[k][j]<edges[i][j]){
                        edges[i][j]=edges[i][k]+edges[k][j];
                    }
                }
            }
        }
        //res
        double res=0.0+INT_MAX;
        for(int j=1;j<=4;j++){
            int p1=4*s+j;
            for(int k=1;k<=4;k++){
                int p2=4*t+k;
                res=min(res,edges[p1][p2]);
            }
        }
        printf("%.1f\n",res);
    }
    return 0;
}